import React, { Suspense, lazy } from "react";
// import  Demo  from './Demo/Demo'
import { HashRouter as Hash, useRoutes, Navigate } from "react-router-dom";
// import Login from './logins/Login'
// import Register from './logins/Register'
// import Forgetpass from './logins/Forgetpass'
import { Loading } from "../components/Loading";
import ErrorRoutes from "./errorpages/route";
import MainRoutes from "./mains/route";

//路由懒加载
const Login = lazy(() => import("./logins/Login"));
const Register = lazy(() => import("./logins/Register"));
const Forgetpass = lazy(() => import("./logins/Forgetpass"));
const Demo = lazy(() => import("./Demo/Demo"));

const MainIndex = () => {
  return (
    <div className="mains">
      <LayoutConfig />
      {/* <h2>主视图--index</h2>
        <Demo uid='2114' updataOne={()=>{}} getList={()=>{}}/> */}
    </div>
  );
};

const LayoutConfig = () => {
  return (
    <Hash>
      <Suspense fallback={Loading()}>
        <RouterIndex></RouterIndex>
      </Suspense>
    </Hash>
  );
};

const RouterIndex = () => {
  const elements = useRoutes([
    {
      path: "/",
      element: <Navigate replace to="/login" />,
    },
    {
      path: "/demo",
      element: <Demo />,
    },
    {
      path: "/login",
      element: <Login />,
    },
    {
      path: "/register",
      element: <Register />,
    },
    {
      path: "/forgetpass",
      element: <Forgetpass />,
    },
    ...ErrorRoutes,
    ...MainRoutes,

    {
      path: "*",
      element: <Navigate replace to="/404"></Navigate>,
    },
  ]);

  return elements;
};

export default MainIndex;
